package com.jscloud.bigdata.zk.lock;

import java.util.concurrent.CountDownLatch;

public class LockApp {
        public static void main(String[] args) {
                final CountDownLatch countDownLatch = new CountDownLatch(10);
                for (int i = 0; i < 10; i++) {
                        new Thread(new Runnable() {
                                @Override
                                public void run() {
                                        DistributedLocks lock = null;
                                        try {
                                                countDownLatch.await();
                                                lock = new DistributedLocks();
                                                lock.lock();

                                                //todo  自行增加需要处理逻辑

                                                System.out.println("获得了锁");
                                                Thread.sleep(2000);
                                        } catch (InterruptedException e) {
                                                throw new RuntimeException(e);
                                        } finally {
                                                lock.unlock();
                                        }

                                }
                        },  "Thread-" + i).start();
                        countDownLatch.countDown();
                }

        }
}
